@extends('back.common.layout')
@section('title', '添加__TITLE__')

@section('content')
    <div id="content">
        <div class="page-header">
            <div class="container-fluid">
                <div class="pull-right">
                    <button type="submit" form="form-brand" data-toggle="tooltip" title="保存" class="btn btn-primary"> <i class="fa fa-save"></i>
                    </button>
                    <a href="{{route('__WEB__.list')}}" data-toggle="tooltip" title="取消" class="btn btn-default"> <i class="fa fa-reply"></i>
                    </a>
                </div>
                <h1>商品__TITLE__</h1>
                <ul class="breadcrumb">
                    <li>
                        <a href="{{url('admin/index')}}">首页</a>
                    </li>
                    <li>
                        <a href="{{route('__WEB__.set')}}">商品__TITLE__</a>
                    </li>
                </ul>
            </div>
        </div>
        <div class="container-fluid">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title">
                        <i class="fa fa-pencil"></i>
                        设置商品__TITLE__
                    </h3>
                </div>
                <div class="panel-body">
                    <!-- __ACTION__ -->
                    <form action="{{route('__WEB__.set')}}" method="post" enctype="multipart/form-data" id="form-__VIEW__" class="form-horizontal">
                        {{ csrf_field() }}
                        @if (isset($__VIEW__->id))
                            <input type="hidden" name="id" id="input-__VIEW___id" value="{{$__VIEW__->id}}">
                        @endif
                        <ul class="nav nav-tabs">
                            <li class="active">
                                <a href="#tab-general" data-toggle="tab">基本信息</a>
                            </li>
                        </ul>
                        <div class="tab-content">
                            <div class="tab-pane active" id="tab-general">

                                __FIELD__
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
@endsection

@section('appendJS')
    <script src="{{asset('/back/validate/jquery.validate.min.js')}}"></script>
    <script src="{{asset('/back/validate/additional-methods.min.js')}}"></script>
    <script src="{{asset('/back/validate/localization/messages_zh.min.js')}}"></script>

    <script>
        $(function() {
            $('#form-__VIEW__').validate({
                rules:{
                    title: {
                        required: true,
                        remote: {
                            url: '{{route('ajax.validator', ['name' => '__VIEW__'])}}',
                            data: {
                                'id': $('#input-__VIEW___id').size()==1 ? $('#input-__VIEW___id').val() : 0
                            }
                        }
                    }
                },
                messages: {
                    title: {
                        required: '__TITLE__不能为空',
                        remote: '__TITLE__已经存在'
                    }
                },

                errorClass: 'text-danger',
                // 处理错误元素的位置
                // error, 错误信息元素
//                element, 出现错误的input元素
                errorPlacement: function(error, element) {
                    // 自己的行为, 设置has-error类
                    element.parents('div.form-group').addClass('has-error');

                    // 默认行为
                    error.appendTo(element.parent());
                },
                // 元素校验通过触发
                success: function (label, element) {
                    // 自己行为, 去掉has-error
                    $(element).parents('div.form-group').removeClass('has-error');
                    // 默认行为
                    label.empty().hide();
                }
            });
        });
    </script>
@endsection